package util

import (
	"os"
	"path/filepath"
)

// AbsPath 获取main下的配置文件路径
func AbsPath(fileName string) (string, error) {
	ex, err := os.Executable()
	if err != nil {
		return "", err
	}
	exPath := filepath.Dir(ex)
	_, err = os.Stat(exPath + "/" + fileName)
	if err != nil {
		if fileName == "alert.log" {
			_, err = os.Create(exPath + "/alert.log")
			if err != nil {
				return "", err
			}
		}
		return "", err
	}
	absPath := exPath + "/" + fileName
	return absPath, nil
}
